package com.ruoyi.edh.domain;

import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.edh.mapper.EdhMicroshopGoodsMapper;
import com.ruoyi.edh.mapper.EdhShoppingCartMapper;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.SearchEntity;

import java.util.Map;

/**
 * 易订货-购物车对象 edh_shopping_cart
 * 
 * @author xxx
 * @date 2020-09-02
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("易订货-购物车")
public class EdhShoppingCart extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键id */
    @ApiModelProperty("主键id")
    private Long id;

    /** 微店id */
    @ApiModelProperty("微店id")
    private Long microshopId;

    /** 商品规格id */
    @Excel(name = "商品规格id")
    @ApiModelProperty("商品规格id")
    private Long goodsSpecificationsId;

    /** 数量 */
    @Excel(name = "数量")
    @ApiModelProperty("数量")
    private Integer amount;

    /** 状态 0正常1失效 */
    @Excel(name = "状态 0正常1失效")
    @ApiModelProperty("状态 0正常1失效")
    private Integer status;

    /** 是否删除0否1是 */
    @ApiModelProperty("状态 0正常1失效")
    private Integer delFlag;

    /** 微店商品id使购物车商品失效 */
    public static Integer killGoodsBymircoGoodsId(Long microshopGoodsId){
        // 找出店铺id和商品id
        EdhMicroshopGoodsMapper microshopGoodsMapper = SpringUtils.getBean(EdhMicroshopGoodsMapper.class);
        Map<String, Long> map = microshopGoodsMapper.loadID(microshopGoodsId);
        EdhShoppingCartMapper shoppingCartMapper = SpringUtils.getBean(EdhShoppingCartMapper.class);
        // 使店铺id和商品id对应的购物车处于失效状态
        return shoppingCartMapper.killGoodsBymircoGoodsId(map.get("shopId"),map.get("goodsId"));

    }

    /** 商品id使购物车商品失效 */
    public static Integer killGoodsByGoodsId(Long microshopGoodsId){
		// 找出店铺id和商品id
		EdhShoppingCartMapper shoppingCartMapper = SpringUtils.getBean(EdhShoppingCartMapper.class);
		// 使店铺id和商品id对应的购物车处于失效状态
		return shoppingCartMapper.killGoodsByGoodsId(microshopGoodsId);
    }
}
